/**
 * https://leetcode-cn.com/problems/count-number-of-nice-subarrays/
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
 var numberOfSubarrays = function (nums, k) {
    let count = 0;
    const hashCount = { 0: 1 };
    let lastSum = 0;
    for (let i = 0; i < nums.length; i++) {
        const sum = lastSum + nums[i] % 2;
        hashCount[sum] = (hashCount[sum] || 0) + 1;
        if (sum >= k && hashCount[sum - k]) {
            count += hashCount[sum - k];
        }
        lastSum = sum;
    } 
    return count;
};